Ext.namespace("Dudley");
Ext.namespace("Dudley.lims");

Dudley.lims.gallerymgr = function() {

    var loaded = false;
    var galleryPanel = {};
    Ext.History.init();
    var tokenDelimiter = ':';

    /*var phyloPanel = new Ext.Panel({
            id: "doligoPanelId",
            autoHeight: true,
            border: true,
            renderTo: "pg-form",
            title: "Phylogenetic tree",
            html: "some html",
            header: false
        });
        phyloPanel.on("activate", function () {
            alert("activating phylo tree, load items!");
        });
    */
   /* Ext.History.on('change', function(token) {
        if (token) {
            var parts = token.split(tokenDelimiter);
            var tabPanel = Ext.getCmp(parts[0]);
            var tabId = parts[1];
            tabPanel.show();
            tabPanel.setActiveTab(tabId);
        } else {
            galleryPanel.setActiveTab(0);
            galleryPanel.getItem(0).setActiveTab(0);
        }
    });
    */
    // public
    return {

        getGalleryLoaded: function() {
            return loaded;
        },

        getGalleryPanel: function() {
            return galleryPanel;
        },

        clearPane: function() {
            Ext.getDom("gallery-form").innerHTML = "";
        },

        loadGallery: function() {
            var pvwin = new Ext.Window({
                title: 'Gallery Loading...',
                width: 400,
                minWidth: 350,
                height: 150,
                modal: true,
                closeAction: 'hide',
                bodyStyle: 'padding:10px;',
                html: "Initializing Gallery...",
                bbar: new Ext.ux.StatusBar({
                    id: 'init-yo-statusbar',
                    defaultText: 'Ready'
                })
            });
            pvwin.on("show", function () {
                var sb = Ext.getCmp("init-yo-statusbar");
                sb.showBusy();
            });
            pvwin.show();
           
            if (!loaded) {
                    loadKaryomapStatic("pg-canvas", function(mockform) {
                    pvwin.close();
                    loaded = true;
                    galleryPanel = new Ext.TabPanel({
                        autoHeight: true,
                        //tbar: mytbar,
                        activeTab: 1,
                        border: true,
                        renderTo: "content-gallery",
                        items: [ mockform, Dudley.lims.PhyloTree.getPhyloPanel()]

                    });

                });
            }
        }
    };
}();
